/*
 * @Author: your name
 * @Date: 2021-09-06 13:43:34
 * @LastEditTime: 2021-09-07 15:14:15
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /wx-weapp/enhancer/router/index.js
 */
export const EventDatas = {}
export function listenerPage(params){
  let onShowHook = params.onShow
  let onHideHook = params.onHide
  let onUnloadHook = params.onUnload
  const watcher = function(curPage,lastPage){
    if(curPage?.route === lastPage?.route) return
    let func = params?.watch?.$router || function(){}
    func(curPage,lastPage)
  }
  params.onShow = function(){
    EventDatas.currentPage = this
    watcher(EventDatas.currentPage,EventDatas.lastPage)
    onShowHook && onShowHook.call(this)
  }
  params.onHide = function(){
    EventDatas.lastPage = this
    watcher(EventDatas.currentPage,EventDatas.lastPage)
    onHideHook && onHideHook.call(this)
  }
  params.onUnload = function(){
    EventDatas.lastPage = this
    watcher(EventDatas.currentPage,EventDatas.lastPage)
    onUnloadHook && onUnloadHook.call(this)
  }
}